Skip to content

Give MoleculeViewModel a frame clock on the JVM - #3373

Closed
StylianosGakis wants to merge 1 commit into
developfrom
fix/molecule-jvm-frame-clock
Closed

StylianosGakis wants to merge 1 commit into
developfrom
fix/molecule-jvm-frame-clock

Conversation

@StylianosGakis

Copy link
Copy Markdown
Member
🤖 AI description

Makes MoleculeViewModel work on the JVM target. Its dispatcher there had no frame clock, so the molecule threw A MonotonicFrameClock is not available in this CoroutineContext inside the stateIn coroutine, where it was swallowed: presenters never ran and nothing was logged. That blocks running the app on desktop, which is where this is heading.

The JVM dispatcher now carries a small clock that completes each frame request 16 ms after it is made. It is delay based because a ViewModel cannot reach a desktop window's own frame clock, and so it also works under a test dispatcher. It costs nothing while idle: the recomposer only asks for a frame after an invalidation.

Only the JVM source set changes. No existing test constructed a MoleculeViewModel (they drive presenters directly), so the new test is the first to cover this path.

Not yet exercised in a real desktop window.

RecompositionMode.ContextClock needs a MonotonicFrameClock in the
coroutine context. Dispatchers.Main on the JVM carries none, so a
MoleculeViewModel's presenter failed inside the sharing coroutine and
uiState never moved past its initial value. The JVM actual now adds a
clock that hands out a frame every 16 ms through delay, which runs on the
Swing timer in a desktop app and on virtual time under a test dispatcher.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant